import java.util.Scanner;

public class DripGame {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] cells = new int[n];
        for (int i = 0; i < n; i++) {
            cells[i] = scanner.nextInt();
        }
        scanner.close();

        int result = playGame(cells, 0);
        System.out.println(result);
    }

    private static int playGame(int[] cells, int drops) {
        int minDrops = Integer.MAX_VALUE;

        for (int i = 0; i < cells.length; i++) {
            if (cells[i] < 6) {
                int[] newCells = cells.clone();
                newCells[i] += 1;
                minDrops = Math.min(minDrops, playGame(newCells, drops));
            }
        }

        for (int i = 0; i < cells.length; i++) {
            if (cells[i] == 6) {
                int left = i - 1;
                int right = i + 1;

                while (left >= 0 && cells[left] == 6) {
                    left--;
                }

                while (right < cells.length && cells[right] == 6) {
                    right++;
                }

                if (left >= 0) {
                    int[] newCells = cells.clone();
                    newCells[i] = 0;
                    newCells[left] += 1;
                    minDrops = Math.min(minDrops, playGame(newCells, drops + 1));
                }

                if (right < cells.length) {
                    int[] newCells = cells.clone();
                    newCells[i] = 0;
                    newCells[right] += 1;
                    minDrops = Math.min(minDrops, playGame(newCells, drops + 1));
                }
            }
        }

        if (minDrops == Integer.MAX_VALUE) {
            return drops;
        } else {
            return minDrops;
        }
    }
}
